/*!	brief	The Clock class is used to know how many time elapsed from a start point
 *			It could also be used to fire a function when it reach a certain value
 *			The clock are all updated by the Application static class
 */

 Clock	=	function()
{
	/************************************/
	/*			Properties				*/
	/************************************/
	
		this.m_Start;			/*!<	Start time, in ms, of the clock	*/
		this.m_Countdown;		/*!< 	If enable, time before the clock end	*/
		
		this.m_Slot		=	new Array();			/*!<	Functions executed when the clock run out	*/
		
	/************************************/
	/*			Constructor				*/
	/************************************/
	
		this.Start();
		
		Clock.Clocks.push(this);
}

	/************************************/
	/*			Methods					*/
	/************************************/
			
		Clock.prototype.Start			=	function(countdown)
		{
			this.m_Start 		= 	Clock.GetTime();
			this.m_Countdown	=	countdown;
		}

		Clock.prototype.AddSlot		=	function(func)
		{
			this.m_Slot.push(func);
		}

		Clock.prototype.TimeElapsed		=	function()
		{
			return Clock.GetTime() -this.m_Start;
		}

		Clock.prototype.Fire		=	function()
		{
			for(var i = 0; i< this.m_Slot.length ; i++)
			{
				this.m_Slot[i].Fire(this.m_Countdown);
			}
		}

		Clock.prototype.Update			=	function()
		{
			if(this.m_m_Countdown!=undefined)
			{
				if(Clock.GetTime() > this.TimeElapsed()+this.m_CountDown)
				{
					return true;
				}
			}
			return false;
		}

	/************************************/
	/*			Static					*/
	/************************************/
	
		/************************************/
		/*			Properties				*/
		/************************************/
		
			Clock.Clocks	=	new Array();	/*!<	Store all clock created by the developpers	*/
			
		/************************************/
		/*			Methods					*/
		/************************************/

			Clock.GetTime	= function()
			{
				date = new Date();
				return date.getTime();
			}			
			
			Clock.Update	=	function()
			{
				var	remove	=	new Array();
				for(var i =0; i< Clock.Clocks.length; i++)
				{
					if(Clock.Clocks[i].Update())
					{
						remove.push(i);
					}
				}
				
				while(remove.length>0)
				{
					Clock.Clocks.splice(remove.pop(),1);
				}
			}